package com.stone.inventory.sharding.config.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

/**
 * 库存分片整体配置
 *
 * @author Mr_wenpan@163.com 2021-07-23
 */
@ConfigurationProperties(prefix = "stone.inv.db")
@Data
public class DbShardingProperty {

    /**
     * 是否分片
     */
    private boolean sharding;

    /**
     * 数据库schema
     */
    private String schema;

    /**
     * 实例Id [必须保证唯一]
     */
    private Long instanceId;

    /**
     * 配置属性
     */
    private Map<String, Object> config;

    /**
     * sharding-jdbc的配置
     */
    private Properties props = new Properties();

    /**
     * 分片规则
     */
    private Map<String, TableRuleProperty> tableRules;

    /**
     * 全局的分片主键规则
     */
    private GlobalIdProperties shardingIdRule;

    public DbShardingProperty() {
        config = new HashMap<>();
        tableRules = new LinkedHashMap<>();
        shardingIdRule = new GlobalIdProperties();
    }
}
